package unr.sytes.net.bean;

import java.io.IOException;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;

/**
 * Bean manejado que administra las redirecciones del menu principal de la
 * aplicacion.
 *
 * @author eagle
 */
@ManagedBean(name = "flujoBean")
@ViewScoped
public class FlujoBean implements Serializable {

    private String contexto = "/goal-programming";

    public void solGrafica() throws IOException {
        ExternalContext ctx = FacesContext.getCurrentInstance().getExternalContext();
        String home = ((HttpServletRequest) ctx.getRequest()).getRequestURL().toString();
        home = home.substring(0, home.indexOf(getContexto()));
//        System.out.println("home: " + home);
        ctx.redirect(home + getContexto() + "/grafica.jsf");
    }

    public void solEstocastica() throws IOException {
        ExternalContext ctx = FacesContext.getCurrentInstance().getExternalContext();
        String home = ((HttpServletRequest) ctx.getRequest()).getRequestURL().toString();
        home = home.substring(0, home.indexOf(getContexto()));
//        System.out.println("home: " + home);
        ctx.redirect(home + getContexto() + "/estocastica.jsf");
    }

    public void nosotros() throws IOException {
        ExternalContext ctx = FacesContext.getCurrentInstance().getExternalContext();
        String home = ((HttpServletRequest) ctx.getRequest()).getRequestURL().toString();
        home = home.substring(0, home.indexOf(getContexto()));
//        System.out.println("home: " + home);
        ctx.redirect(home + getContexto() + "/nosotros.jsf");
    }

    public void ayuda() throws IOException {
        ExternalContext ctx = FacesContext.getCurrentInstance().getExternalContext();
        String home = ((HttpServletRequest) ctx.getRequest()).getRequestURL().toString();
        home = home.substring(0, home.indexOf(getContexto()));
//        System.out.println("home: " + home);
        ctx.redirect(home + getContexto() + "/ayuda.jsf");
    }

    public void indexPage() throws IOException {
        ExternalContext ctx = FacesContext.getCurrentInstance().getExternalContext();
        String home = ((HttpServletRequest) ctx.getRequest()).getRequestURL().toString();
        home = home.substring(0, home.indexOf(getContexto()));
//        System.out.println("home: " + home);
        ctx.redirect(home + getContexto() + "/index.jsf");
    }

    public String getContexto() {
        return contexto;
    }

    public void setContexto(String contexto) {
        this.contexto = contexto;
    }
}
